package com.ma.servlet;

import com.ma.utils.Constant;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端请求的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if(username.equals("admin")&&password.equals("admin")){//登陆成功
            System.out.println("登陆成功");
            req.getSession().setAttribute(Constant.User_SESSION,req.getSession().getId());
            resp.sendRedirect("/sys/success.jsp");
        }else { //登陆失败
            resp.sendRedirect("/error.jsp");


        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
